package com.zr.kucunkufangbiaoshi.controller.controller;


import com.zr.kucunkufangbiaoshi.controller.meiju.StatusEnum;
import com.zr.kucunkufangbiaoshi.controller.meiju.XiaLaVo;
import com.zr.kucunkufangbiaoshi.controller.pojo.WareHouseIdentifyAddVo;
import com.zr.kucunkufangbiaoshi.controller.pojo.WareHouseIdentifySelectVo;
import com.zr.kucunkufangbiaoshi.controller.pojo.WareHouseIdentifyStatusVo;
import com.zr.kucunkufangbiaoshi.controller.pojo.WareHouseIdentifyUpdateVo;
import com.zr.kucunkufangbiaoshi.controller.service.WareHouseIdentifyService;
import com.zr.kucunkufangbiaoshi.controller.util.ResultBuildVo;
import com.zr.kucunkufangbiaoshi.controller.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2019/7/16 0016.
 */

@RestController
@RequestMapping("eeeeeeee/")
public class WareHouseIdentifyController {
    @Autowired
    private WareHouseIdentifyService wareHouseIdentifyService;

    /**
     * 分页
     * @param wareHouseIdentifySelectVo
     * @return
     */
    @PostMapping("queryPage")
    public ResultVo queryPage(@RequestBody WareHouseIdentifySelectVo wareHouseIdentifySelectVo){
        return wareHouseIdentifyService.queryPage(wareHouseIdentifySelectVo);
    }

    /**
     * 新增
     * @param wareHouseIdentifyAddVo
     * @param bindingResult
     * @return
     */
    @PostMapping("add")
    public ResultVo add(@RequestBody @Valid WareHouseIdentifyAddVo wareHouseIdentifyAddVo, BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage(),"500");
        }
        return  wareHouseIdentifyService.add(wareHouseIdentifyAddVo);
    }
    /**
     * 状态下拉框
     */
    @GetMapping("startEnd")
    public ResultVo<List<XiaLaVo>> queryXiaLa(){

        List<XiaLaVo> xiaLaVoList = new ArrayList<>();
        for (int i = 0; i< StatusEnum.values().length; i++){
            XiaLaVo xiaLaVo = new XiaLaVo();
            xiaLaVo.setValue(i);
            xiaLaVo.setLabel(StatusEnum.getName(i));
            xiaLaVoList.add(xiaLaVo);
        }
        return ResultBuildVo.success(xiaLaVoList);
    }
    /**
     * 修改状态接口
     * @param
     * @param bindingResult
     * @return
     */
    @PostMapping("updateStatus")
    public ResultVo updateStatus(@RequestBody @Valid WareHouseIdentifyStatusVo wareHouseIdentifyStatusVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage(),"500");
        }
        return wareHouseIdentifyService.updateStatus(wareHouseIdentifyStatusVo);
    }
    /**
     * 修改接口
     */
    @PostMapping("update")
    public ResultVo update(@RequestBody @Valid WareHouseIdentifyUpdateVo wareHouseIdentifyUpdateVo, BindingResult bindingResult){

        if (bindingResult.hasErrors()){
            return ResultBuildVo.error(bindingResult.getFieldError().getDefaultMessage(),
                    "500");
        }
        return wareHouseIdentifyService.update(wareHouseIdentifyUpdateVo);

    }
}
